package com.java.interview.i设计模式.建造者模式;

/**
 * demo类
 *
 * @Description:建造者模式
 * @Auther: sixbing  QQ:414409451
 * @Date: 2018/12/17 13:51
 */
public class BuilderDemo {
    private int age;
    private String name;

    public BuilderDemo() {
        this(new Builder());
    }

    public int getAge() {
        return age;
    }

    public String getName() {
        return name;
    }

    private BuilderDemo(Builder builder) {
        this.age = builder.age;
        this.name = builder.name;
    }

    public static final class Builder {
        private int age;
        private String name;

        public Builder() {
            age = 0;
            name = "name";
        }

        public Builder setName(String name) {
            this.name = name;
            return this;
        }

        public Builder setAge(int age) {
            this.age = age;
            return this;
        }

        public BuilderDemo Builder() {
            return new BuilderDemo(this);
        }
    }
}
